#include "tools.cpp"

class Solution {
  public:
    int countCharacters(vector<string>& words, string chars) {
        std::vector<int> char_map(128, 0);
        for (auto c : chars) char_map[c]++;

        int result = 0;
        for (auto word : words) {
            std::vector<int> char_map_bak{char_map};
            bool successed = true;
            for (auto c : word) {
                if (char_map_bak[c] > 0)
                    char_map_bak[c]--;
                else {
                    successed = false;
                    break;
                }
                std::cout << c << std::endl;
            }
            if (successed) result += word.size();
        }
        return result;
    }
};

int main() {
    Solution s;
    std::vector<string> words{"hat", "cat", "fuck"};
    std::string chars{"hatff"};
    s.countCharacters(words, chars);
}
